package com.lqd.mall.system.repository;

import com.lqd.mall.interaction.system.SysRoleEntity;
import com.lqd.mall.jpa.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 零起点
 * @create 2022-02-20 9:25
 */
public interface SysRoleEntityRepository extends BaseRepository<SysRoleEntity,Long> {

    @Query(value="  select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,\n" +
            "            r.status, r.del_flag, r.create_time, r.remark,r.create_by,r.upate_by,r.upate_time" +
            "        from sys_role r\n" +
            "        left join sys_user_role ur on ur.role_id = r.role_id\n" +
            "        left join sys_user u on u.user_id = ur.user_id\n" +
            "        left join sys_dept d on u.dept_id = d.dept_id where r.del_flag = '0' and ur.user_id = :userId",nativeQuery = true)
    List<SysRoleEntity> findByDelFlagAndUserId(  @Param("userId") Long userId);
}
